import api from '../../api';
import { message } from 'antd';

export default {
  namespace: 'bondAnalysisM',
  state: {
    dictMap: {},
    tableData0: [],
    totalSize0: 0,
    columns0: [],
    tableData1: [],
    totalSize1: 0,
    columns1: [],
    tableData2: [],
    totalSize2: 0,
    columns2: [],
    bondTypeList: [],
  },

  effects: {
    //获取债券表格内容
    *queryCreditBondMonitor({ payload, callback }, { call, put, select }) {
      const res = yield call(api.bondAnalysis.creditBondMonitor, payload);
      if (res && res.code == 0) {
        const tempArr = res.data?.dataSource || [];
        tempArr.map((item, key) => {
          item.key == key;
        });
        callback({
          tableData: tempArr,
          columns: [
            { title: '债券简称', key: 'SYMBOL' },
            { title: '最新成交收益率', key: 'YIELD' },
            { title: '中债估值收益率', key: 'EVALUTEDYIELD' },
            { title: '收益率偏离度（bp）', key: 'YIELDBIAS' },
            { title: '最新成交净价', key: 'TRADENETPRICE' },
            { title: '中债估值净价', key: 'NETVALUATION' },
            { title: '净价偏离度（%）', key: 'NETVALUATIONBIAS' },
            { title: '当日偏离次数', key: 'BIASCNT' },
            { title: '成交次数', key: 'TRANSACTIONCNT' },
            { title: '更新时间', key: 'UPDATETIME' },
          ],
        });
      } else {
        callback({
          tableData: [],
          totalSize: 0,
          columns: [],
        });
        message.error('查询失败');
      }
    },
  },
  reducers: {
    save(state, { payload }) {
      return { ...state, ...payload };
    },
  },
};
